package com.gxa.finance.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.commons.R;
import com.gxa.finance.mapper.ServiceTagMapper;
import com.gxa.common.pojo.ServiceTag;
import com.gxa.finance.service.ServiceTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ServiceTagServiceImpl extends ServiceImpl<ServiceTagMapper, ServiceTag> implements ServiceTagService {

    @Autowired
    private ServiceTagMapper ServiceTagMapper;

    //查询接口
    @Override
    public R findServiceTagList(String serve,Integer price) {
        R r = new R();
        try{
            List<ServiceTag> ServiceTagList = ServiceTagMapper.findServiceTagList(serve,price);
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(ServiceTagList);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("网络开小差");
        }
        return r;
    }

    //新增接口
    @Override
    public R addServiceTag(ServiceTag ServiceTag) {
        R r = new R();
        int result = ServiceTagMapper.insert(ServiceTag);
        if (result > 0) {
            r.setCode(200);
            r.setMsg("添加成功");
        }else {
            r.setCode(500);
            r.setMsg("系统出小差了，请联系管理员");
        }
        return r;
    }

    //删除
    @Override
    public R delServiceTag(ServiceTag ServiceTag) {

        R r = new R();
        int result = ServiceTagMapper.deleteById(ServiceTag);
        if (result > 0) {
            r.setCode(200);
            r.setMsg("删除成功");
        }else {
            r.setCode(500);
            r.setMsg("系统出小差了，请联系管理员");
        }
        return r;

    }

    @Override
    public R updateServiceTag(ServiceTag ServiceTag) {
        R r = new R();
        int result = ServiceTagMapper.updateById(ServiceTag);
        if (result > 0) {
            r.setCode(200);
            r.setMsg("修改成功");
        }else {
            r.setCode(500);
            r.setMsg("系统出小差了，请联系管理员");
        }
        return r;
    }
}
